<html>
<script>
function validate() {
var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.register.username.value.length<1)
	{
		alert("Please enter the Username");
	
	}else if(document.register.password.value.length<1)
	{
		alert("Please enter the password");
	
	}else if(document.register.email.value.length<1)
	{
		alert("Please enter the email id");
		
	}
	else if(!regex.test(document.register.email.value))
	{
		alert("Invalid email address format");
		
	}
	else document.register.submit();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta name="keywords" content="" />

<meta name="description" content="" />

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="js/jquery-latest.pack.js"></script>
</head>
<?php
	session_start();
	include_once "function.php";
?>



<body>

<div id="wrapper">

	<div id="wrapper2">

		<?php include_once 'header.php';?>



		<!-- end #header -->

		<div id="page">

			<div id="content">

				<div class="post">
				<div id='tabb'>
	<?php 			if(isset($_POST['submit'])) {
		if($_POST['username'] == "" || $_POST['password'] == "") {
			$login_error = "One or more fields are missing.";
		}
		else {
			$check = user_pass_check($_POST['username'],$_POST['password']); // Call functions from function.php
			if($check == 1) {
				$login_error = "User ".$_POST['username']." not found.";
			}
			elseif($check==2) {
				$login_error = "Incorrect password.";
			}
			else if($check==0){
				$_SESSION['username']=$_POST['username']; //Set the $_SESSION['username']
				$userid = getUserID($_POST['username']);
				
				$_SESSION['userid']=$userid;
				header("Location: browse.php");
			}		
		}
}


 
?>

	<form name="register" action="Succesful.php" method="post">
<table>
<tr><td>Username : </td><td><input type="text" name="username"/><br/></td></tr>
<tr><td>Password : </td><td><input type="password" name="password"/><br/></td></tr>
<tr><td>Email Id : </td><td><input type="text" name="email"/><br/></td></tr>
<tr><td><input type="button" value="Register" onclick="validate()"></td></tr> 
</table>
</form>

<?php
  if(isset($login_error))
   {  echo "<div id='passwd_result'>".$login_error."</div>";}
?>
				</div>		
				</div>
				</div>
			<!-- end #content -->

			<!-- end #sidebar -->

			<div style="clear: both;">&nbsp;</div>

		</div>

		<!-- end #page -->

		<div id="footer">

			<p>Copyright (c) 2011 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>

		</div>

	</div>

</div>

<!-- end #footer -->

</body>

</html>


<body>

<form name="register" action="Succesful.php" method="post">
<table>
<tr><td>Username : </td><td><input type="text" name="username"/><br/></td></tr>
<tr><td>Password : </td><td><input type="password" name="password"/><br/></td></tr>
<tr><td>Email Id : </td><td><input type="text" name="email"/><br/></td></tr>
<tr><td><input type="button" value="Register" onclick="validate()"></td></tr> 
</table>
</form>
</body>
</html>